package com.king01.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.king01.dao.GoodsDao;
import com.king01.entity.Goods;
import com.king01.entity.*;
import com.king01.service.GoodsService;
import com.king01.util.Ossutils;
import com.king01.vo.GoodsVo;
import com.king01.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author：张梓康
 * @date：Created in 2023/9/26 17:37
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private HttpSession session;

    @Override
    public Result findAllGoods(Integer currentPage, Integer pageSize, GoodsVo goodsVo) {

        PageHelper.startPage(currentPage, pageSize);
        List<Goods> goods = goodsDao.selectAllGoods(goodsVo);
        PageInfo<Goods> pageInfo = new PageInfo<>(goods);
        return new Result(200, "查找所有商品信息成功", pageInfo);
    }

    @Override
    public Integer selectbranchid() {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        return branchid;
    }

    @Override
    public Result findAllKeyCap() {
        List<Keycap> list = goodsDao.selectAllKeyCap();
        return new Result(200, "获取所有键帽类型成功", list);
    }

    @Override
    public Result findAllKeyBoardColor(Integer currentPage, Integer pageSize, Keyboardcolor keyboardcolor, Integer status) {
        PageHelper.startPage(currentPage, pageSize);
        List<Keyboardcolor> list = goodsDao.selectAllKeyColor(keyboardcolor);
        PageInfo<Keyboardcolor> pageInfo = new PageInfo<>(list);
        return new Result(200, "获取所有键盘颜色成功", pageInfo);
    }

    @Override
    public Result findAllShaftChoose(Integer currentPage, Integer pageSize, Integer status) {
        List<Shaftchoose> list = null;
        if (status != null) {
            list = goodsDao.selectAllShaftChoose();
            return new Result(200, "获取所有轴体类型成功", list);
        } else {
            PageHelper.startPage(currentPage, pageSize);
            list = goodsDao.selectAllShaftChoose();
            PageInfo<Shaftchoose> pageInfo = new PageInfo<>(list);
            return new Result(200, "获取所有轴体类型成功", pageInfo);
        }
    }

    @Override
    public Integer deleteGoods(Integer id) {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer delete = goodsDao.delete(id,staff.getBranchid());
        return delete;
    }

    @Override
    public Result findAllBackLightColor(Integer currentPage, Integer pageSize, Integer status) {
        List<Backlightcolor> list = null;
        if (status != null) {
            list = goodsDao.selectAllBackLightColor();
            return new Result(200, "获取所有背光颜色成功", list);
        } else {
            PageHelper.startPage(currentPage, pageSize);
            list = goodsDao.selectAllBackLightColor();
            PageInfo<Backlightcolor> pageInfo = new PageInfo<>(list);
            return new Result(200, "获取所有背光颜色成功", pageInfo);
        }
    }

    @Override
    public Result findAllBranch() {
        List<Branch> list = goodsDao.selectAllBranch();
        return new Result(200, "获取所有分店信息成功", list);
    }

    @Override
    public Result findAllGoods() {
        return null;
    }

    @Override
    public Integer updateGoods(GoodsVo goodsVo) {
        Integer integer = goodsDao.updateGoods(goodsVo);
        return integer;
    }

    @Override
    public Integer addGoods(GoodsVo goodsVo) {
        Integer integer = goodsDao.addGoods(goodsVo);
        return integer;
    }

    @Override
    public Result selectAllGoodsByBranch(Integer currentPage, Integer pageSize) {
        //mybatis-pageHelper插件
        PageHelper.startPage(currentPage, pageSize);
        //获取登陆的session数据
        List<Goods> goods = goodsDao.selectAllGoodsByBranch();
        //把查询的结果封装PageInfo对象中
        PageInfo<Goods> pageInfo = new PageInfo<>(goods);
        return new Result(200, "查找所有商品信息成功", pageInfo);
    }

    @Override
    public Integer deleteKeyBoardColor(Integer keyboardcolorid) {
        Integer integer = goodsDao.deletekeyboardcolor(keyboardcolorid);
        return integer;
    }

    @Override
    public Integer addkeyboardcolor(Keyboardcolor keyboardcolor) {
        Integer integer = goodsDao.addkeyboardcolor(keyboardcolor);
        return integer;
    }


    @Override
    public Integer updatekeyboardcolor(Keyboardcolor keyboardcolor) {
        Integer integer = goodsDao.updatekeyboardcolor(keyboardcolor);
        return integer;
    }

    @Override
    public Integer updateshaftchoose(Shaftchoose shaftchoose) {
        Integer integer = goodsDao.updateshaftchoose(shaftchoose);
        return integer;
    }

    @Override
    public Integer updatebacklightcolor(Backlightcolor backlightcolor) {
        Integer integer = goodsDao.updatebacklightcolor(backlightcolor);
        return integer;
    }

    @Override
    public Integer deleteshaftchoose(Integer shaftchooseid) {
        Integer integer = goodsDao.deleteshaftchoose(shaftchooseid);
        return integer;
    }

    @Override
    public Integer addshaftchoose(Shaftchoose shaftchoose) {
        Integer integer = goodsDao.addshaftchoose(shaftchoose);
        return integer;
    }


    @Override
    public Integer deletebacklightcolor(Integer backlightcolorid) {
        Integer integer = goodsDao.deletebacklightcolor(backlightcolorid);
        return integer;
    }

    @Override
    public Integer addbacklightcolor(Backlightcolor backlightcolor) {
        Integer integer = goodsDao.addbacklightcolor(backlightcolor);
        return integer;
    }

    @Override
    public Result keyboardcolorAll() {
        List<Keyboardcolor> list = goodsDao.selectAllKeyColor(new Keyboardcolor());
        return new Result(200, "获取所有键盘颜色成功", list);
    }

    @Override
    public Result imgUpload(MultipartFile file) {
        String path = Ossutils.ossUpload(file);
        return new Result(200,"上传成功",path);
    }

}
    